package com.wisdytech.linkdcs.tool.action;


import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.bean.StandardTableResult;
import com.wisdytech.common.handler.ResourceMatchingService;
import com.wisdytech.common.utils.BaseUtil;
import com.wisdytech.linkdcs.system.model.SysUser;
import com.wisdytech.linkdcs.tool.model.ToolReplacePlan;
import com.wisdytech.linkdcs.tool.service.IToolReplacePlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhanghailin
 * @since 2018-06-08
 */
@Controller
@RequestMapping("/tool/replacePlan")
public class ToolReplacePlanAction {


    @Resource
    private IToolReplacePlanService toolReplacePlanService;
    @Autowired
    @Qualifier("resourceMatchingService")
    private ResourceMatchingService resourceMatchingService;
    /**
     *
     * <p>Description: 工装更换计划信息</p>
     * @param model model
     * @return String
     */
    @RequestMapping("/index")
    public String toolInfoIndex(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
        return "tool/toolReplacePlan";
    }

    @RequestMapping(value = "/getToolReplacePlanByFilter/get.mvc")
    @ResponseBody
    public StandardTableResult<ToolReplacePlan> getToolReplacePlanByFilter(String toolCode, String toolName, Filter filter) {
        PageInfo<ToolReplacePlan> page = toolReplacePlanService.getToolReplacePlanByFilter(toolCode,toolName,filter);
        return new StandardTableResult<>(page.getTotal(),page.getList());
    }

    /**
     * 保存/更新工装更换计划信息
     * @param toolReplacePlan 实体类
     * @return StandardResult
     */
    @RequestMapping(value = "/saveOrUpdateToolReplacePlan/save.mvc")
    @ResponseBody
    public StandardResult saveOrUpdateToolReplacePlan(ToolReplacePlan toolReplacePlan) {
        SysUser user = BaseUtil.getCurrentUser();
        this.toolReplacePlanService.saveOrUpdateToolReplacePlan(toolReplacePlan,user);
        return StandardResult.getSuccessResult();
    }

    /**
     *
     * @param pkIds 主键
     * @return StandardResult
     */
    @RequestMapping(value = "/deleteToolReplacePlan/del.mvc")
    @ResponseBody
    public StandardResult deleteToolReolacePlan(String pkIds) {
        SysUser operator = BaseUtil.getCurrentUser();
        this.toolReplacePlanService.deleteToolReolacePlan(pkIds,operator);
        return StandardResult.getSuccessResult();
    }

    /**
     *
     * @param pkId 主键
     * @return StandardResult
     */
    @RequestMapping(value = "/getToolReplacePlanById/get.mvc")
    @ResponseBody
    public StandardResult getToolReplacePlanById(String pkId) {
        ToolReplacePlan t = this.toolReplacePlanService.getToolReplacePlanById(pkId);
        return StandardResult.getSuccessResult(t);
    }

}

